package com.qmhl.toolposition.activity

import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.hjq.toast.Toaster
import com.qmhl.toolposition.api.UserService
import com.qmhl.toolposition.base.BaseActivity
import com.qmhl.toolposition.databinding.ActivityCommitFeedbackBinding
import kotlinx.coroutines.launch

class CommitFeedbackActivity : BaseActivity() {

    private lateinit var binding: ActivityCommitFeedbackBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityCommitFeedbackBinding.inflate(layoutInflater)
        setContentView(binding.root)
    }

    override fun initData() {
        super.initData()
    }

    override fun initListener() {
        super.initListener()

        binding.ivBack.setOnClickListener {
            finish()
        }

        binding.btnFeedback.setOnClickListener {
            feedBackCommit()
        }
    }

    private fun feedBackCommit() {

        var feedBack = binding.etFeedback.text.toString()
        var contact = binding.etContact.text.toString()

        if (feedBack.isEmpty()) {
            Toaster.showShort("请输入您的问题")
            return
        }
        if (contact.isEmpty()) {
            Toaster.showShort("请输入您的联系方式")
            return
        }


        lifecycleScope.launch {
            var content = UserService.create()
                .feedBack(feedBack, contact)
            if (content.code == 200) {
                Toaster.showShort(content.msg)
                finish()
            } else {
                Toaster.showShort(content.msg)
            }
        }

    }
}